<?php
class MHDEV_View_Helper_IsBanned extends Zend_View_Helper_Abstract
{
    public function IsBanned($uid, $thread_uid = false, $board_uid = false)
    {
		// db
		$bans 			= new Bans();
		$threads		= new Threads();
		$boards			= new Boards();
		
		if($thread_uid)
		{
			// query
			$getThread		= $threads->find($thread_uid);
			
			if($getThread->count() > 0)
			{
				$resThread		= $getThread->toArray();
	
				$getBoard		= $boards->find($resThread[0]['board_uid']);
				$resBoard		= $getBoard->toArray();
				
				$getBan			= $bans->fetchAll('`is_deleted` = 0 AND `user_uid` = ' . $uid . ' AND `expire_date` > CURDATE() AND (`thread_uid` = ' . $thread_uid . ' OR `board_uid` = ' . $resThread[0]['board_uid'] . ')');
				
				return $getBan->toArray();
			}
		}
		elseif($board_uid)
		{
			// query
			$getBoard		= $boards->find($board_uid);
			
			if($getBoard->count() > 0)
			{
				$resBoard		= $getBoard->toArray();
				
				$getBan			= $bans->fetchAll('`is_deleted` = 0 AND `user_uid` = ' . $uid . ' AND `expire_date` > CURDATE() AND `board_uid` = ' . $resBoard[0]['uid']);
				
				return $getBan->toArray();
			}
		}
		
		return false;
    }
}
?>